<template>
    <view class="wxWrap" @click="showmodel" v-if="show.show">
        <view @click.stop="showcon">
            <view class="wxWrap_t">创业伯乐</view>
            <view @click.stop="stopClick">
                <u-button class="button" type="primary" @click="bindgetuserinfo" v-if="show.islogin">使用微信登陆</u-button>
                <u-button class="button" type="primary"  v-if="show.isphone" @click="updUserPhone">手机号登录</u-button>
            </view>
        </view>

    </view>
</template>

<script>
export default {
  name: "wxAuth",
  props: {
    isshow: {
      type: Object,
    },
  },
  watch: {
    isshow (newval, oldval) {
      this.show = newval
    }
  },
  data () {
    return {
      show: {
        show: false,
        islogin: false,
        isphone: false
      }
    }
  },
  methods: {
    stopClick () {
      this.show.show = false
    },
    showcon () {
      this.show.show = true
    },
    showmodel () {
      this.show.show = false
      this.$emit('changeshow', this.show)
    },
    bindgetuserinfo () {
      // this.show.show = true
      let _this = this;
     
      uni.getUserProfile({
        desc:'登录创业伯乐',
        success: res => {
         
          // global.wxLogin()
          if (global.wxLogin(res)) {
            this.show.islogin = false
            this.show.show = false

            setTimeout(() => {
             
              this.$emit('changeshow', this.show)
              this.$emit('userInfo', {
                ...res.userInfo,
                nickname:res.userInfo?.nickName,
                avatar:res.userInfo?.avatarUrl,
              })
              uni.setStorageSync('userInfo',{
                ...res.userInfo,
                nickname:res.userInfo?.nickName,
                avatar:res.userInfo?.avatarUrl,
              })
            }, 500)
          }
        },
        fail () {
          console.log('拒绝授权')
          _this.$emit('changeshow', _this.show)
        }
      })
    },
    bindgetphonenumber (e) {
      if (e.detail) {
        this.miniGetPhone(e)
      }
    },
    // async miniGetPhone (e) {
    //   let res = await global.miniGetPhone({
    //     encryptedData: e.detail.encryptedData,
    //     iv: e.detail.iv,
    //     session_key: wx.getStorageSync('session_key'),
    //   })
    //   if (res.data.code == 200) {
    //     uni.setStorageSync('uPhone', res.data.uphone)
    //     this.updUserPhone(res.data.uphone)
    //   }
    // },
     updUserPhone () {
        uni.navigateTo({
                url:'/pages/userInfo/mobile'
            })
    }
  }
}
</script>

<style scoped lang="scss">
.wxWrap {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.8);
  > view {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 60upx;
    background: white;
    border-radius: 40upx 40upx 0upx 0upx;
    padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
    box-sizing: border-box;
  }
  &_t {
    font-size: 48upx;
    font-weight: bold;
    color: #333333;
    margin-bottom: 38upx;
  }
  &_f {
    color: #666666;
    font-size: 44upx;
    margin-bottom: 80upx;
  }
}
</style>